<html>
<head><meta charset="utf-8"><title>Ty from DefId · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html">Ty from DefId</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213761196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213761196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213761196">(Oct 19 2020 at 09:31)</a>:</h4>
<p>Hi. If in compiler code I have a <code>DefId</code> for a lang item that I’m adding for a struct, can get a <code>Ty</code> for that struct?</p>



<a name="213761518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213761518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213761518">(Oct 19 2020 at 09:34)</a>:</h4>
<p>For context: I’m having a go at implementing by pointer metadata RFC which adds a <code>Pointee</code> trait that is automatically implemented for all type and has an associated type, much like <code>DiscriminantKind</code>. It looks like a <code>Ty</code> is needed when projecting that associated type: <a href="https://github.com/rust-lang/rust/blob/cb2462c53f2cc3f140c0f1ea0976261cab968a34/compiler/rustc_trait_selection/src/traits/project.rs#L1248">https://github.com/rust-lang/rust/blob/cb2462c53f2cc3f140c0f1ea0976261cab968a34/compiler/rustc_trait_selection/src/traits/project.rs#L1248</a></p>



<a name="213761572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213761572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213761572">(Oct 19 2020 at 09:35)</a>:</h4>
<p>(And <code>&lt;dyn SomeTrait as Pointee&gt;::Metadata</code> is a new <code>DynMetadata</code> struct that I’m also adding, that makes the vtable pointer opaque)</p>



<a name="213762581"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213762581" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213762581">(Oct 19 2020 at 09:46)</a>:</h4>
<p>what's the result of <code>tcx.type_of(def_id)</code>?</p>



<a name="213763000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213763000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213763000">(Oct 19 2020 at 09:50)</a>:</h4>
<p>Looks like this is it! The actual signature is much more generic so it wasn’t obvious that this returns a <code>Ty</code>…<br>
<a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.type_of">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.type_of</a></p>



<a name="213763009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213763009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213763009">(Oct 19 2020 at 09:50)</a>:</h4>
<p>thanks</p>



<a name="213763296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213763296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213763296">(Oct 19 2020 at 09:53)</a>:</h4>
<p>yeah, the query output types are currently a bit of a mess sadly</p>



<a name="213763419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213763419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213763419">(Oct 19 2020 at 09:54)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> is looking into normalizing projections in rustdoc but that's quite hard</p>



<a name="213775453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213775453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213775453">(Oct 19 2020 at 12:09)</a>:</h4>
<p>Yeah the current issue is I need to know the generic context to get a <code>ParamEnv</code>, and rustdoc does things in (<em>literally</em>) 20 different places so I'd rather not update all of them with the new behavior, since it will be silently ignored if missing</p>



<a name="213775549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213775549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213775549">(Oct 19 2020 at 12:10)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/78082">https://github.com/rust-lang/rust/pull/78082</a>, <a href="https://github.com/rust-lang/rust/pull/77467">https://github.com/rust-lang/rust/pull/77467</a></p>



<a name="213779076"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Ty%20from%20DefId/near/213779076" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Ty.20from.20DefId.html#213779076">(Oct 19 2020 at 12:44)</a>:</h4>
<p>personally I think 77467 could be landed as-is since it just doesn't handle all cases, but <span class="user-mention silent" data-user-id="119009">eddyb</span> is worried about ICEs</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>